// 杂项
const commonMixin = {
	data(){
		return{
			showInput: false,
			focus: false,
			input_placeholder: '我要提问...',
			allow: true,
			downOption: {
				use: false
			},
			upOption: {
				use: false,
				toTop: {
					src: ''
				}
			},
			//tab内容设定
			tabs: [ { name: '互动' } ],
			//当前Tab
			currentTab: 0,
			// 是否允许自动下滑
			canScroll: true,
			// 是否显示倒计时时钟
			showClock: false,
			// 时钟倒计时时长
			clockTime: 0,
			// 时钟定时器
			clockTimer: ''
		}
	},
	computed: {
		//出勤小标题dom
		subCheckTitle:function(){
			return len=>{
				return `共<span style='color:${this.theme.danger}'>${len}</span>人出勤`
			}
		},
		//缺勤小标题dom
		subUnCheckTitle:function(){
			return len=>{
				return `共<span style='color:${this.theme.danger}'>${len}</span>人缺勤`
			}
		},
		//文字长度限定
		subText:function(){
			return (val, len)=>{
				if(!val){
					return ''
				}
				return val.length>len?`${val.substring(0, len)}...`:val
			}
		},
		// 上课倒计时文本
		clockStr(){
			if(!this.clockTime || this.clockTime == 0){
				return "00:00"
			}else{
				let min = Math.floor(this.clockTime/60)
				let sec = this.clockTime%60
				return `${min>=10?min:'0'+min}` + ":"+ `${sec>=10?sec:'0'+sec}`;
			}
		}
	},
	onUnload(){
		clearInterval(this.clockTimer)
	},
	methods: {
		// 获取拉流地址
		getLivePlayerInfo() {
			return this.$http.request({
				url: 'api/LivePlayer/GetLivePlayerInfo',
				data: {
					Id: this.Id
				}
			})				
		},
		//全屏状态变更
		fullscreenchange(e){
			if(e.detail.fullScreen){
				this.isFullScreen = true
			}else{
				this.isFullScreen = false
			}
		},
		// 全屏
		fullScreen() {
			this.livePlayer.requestFullScreen({ direction: 90 })
			this.isFullScreen = true;
		},
		// 退出全屏
		exitFullScreen() {
			this.livePlayer.exitFullScreen({ direction: 90 })
			this.isFullScreen = false;
		},
		// 刷新
		resume() {
			uni.showLoading({
				mask: true,
				title: '加载中...'
			});
			setTimeout(()=>{
				uni.hideLoading();
			}, 3000);
			this.livePlayer.play();
		},
		// 滚动到底部
		goBottom(){
			this.canScroll = true
			this.mescroll.scrollTo(99999, 50)
		},
		// 弹出键盘
		goToComment() {
			if (this.allow) {
				this.showInput = true;
				this.$nextTick(function(){
					uni.getSystemInfo().then(resp=>{
						switch (resp[1].platform){
							case 'android':
								this.focus = true
								break
							case 'ios':
								setTimeout(()=>{
									this.focus = true
								}, 100)
								break
						}
					})
				})
			} else {
				uni.showToast({
					icon: 'none',
					title: '全员禁言中...'
				});
			}
		},
		// 键盘获取焦点
		blur() {
			this.init_input();
		},
		init_input() {
			this.showInput = false;
			this.focus = false;
		},
		// 倒计时时钟
		setClock(){
			if(!this.clockTime || this.clockTime == 0){
				this.showClock = false;
			}else{
				this.showClock = true
				this.clockTimer = setInterval(()=>{
					// 计时完毕， 停止定时
					if(this.clockTime <= 0){
						this.showClock = false;
						clearInterval(this.clockTimer);
					}else{
						this.clockTime--
					}
				}, 1000);
			}
		}
	}
}

export default commonMixin;